---
layout: "default"
title: "Operator: &&"
description: "Swift documentation for the '&&' operator."
root: "/v4.2"
---

<code class="language-swift"> operator &amp;&amp; {
    associativity left
    precedence 
}</code>

<h3>Declarations</h3>

<div class="declaration" id="func-ampamp_-bool-rhs_-autoclosure-throws-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-ampamp_-bool-rhs_-autoclosure-throws-bool">func &amp;&amp;(<wbr>_:<wbr> Bool, rhs: @autoclosure () throws -&gt; Bool)</a>
        
<div class="comment collapse" id="comment-func-ampamp_-bool-rhs_-autoclosure-throws-bool"><div class="p">
    <p>Performs a logical AND operation on two Boolean values.</p>

<p>The logical AND operator (<code>&amp;&amp;</code>) combines two Boolean values and returns
<code>true</code> if both of the values are <code>true</code>. If either of the values is
<code>false</code>, the operator returns <code>false</code>.</p>

<p>This operator uses short-circuit evaluation: The left-hand side (<code>lhs</code>) is
evaluated first, and the right-hand side (<code>rhs</code>) is evaluated only if
<code>lhs</code> evaluates to <code>true</code>. For example:</p>

<pre><code class="language-swift">let measurements = [7.44, 6.51, 4.74, 5.88, 6.27, 6.12, 7.76]
let sum = measurements.reduce(0, combine: +)

if measurements.count &gt; 0 &amp;&amp; sum / Double(measurements.count) &lt; 6.5 {
    print(&quot;Average measurement is less than 6.5&quot;)
}
// Prints &quot;Average measurement is less than 6.5&quot;</code></pre>

<p>In this example, <code>lhs</code> tests whether <code>measurements.count</code> is greater than
zero. Evaluation of the <code>&amp;&amp;</code> operator is one of the following:</p>

<ul><li>When <code>measurements.count</code> is equal to zero, <code>lhs</code> evaluates to <code>false</code>
and <code>rhs</code> is not evaluated, preventing a divide-by-zero error in the
expression <code>sum / Double(measurements.count)</code>. The result of the
operation is <code>false</code>.</li><li>When <code>measurements.count</code> is greater than zero, <code>lhs</code> evaluates to
<code>true</code> and <code>rhs</code> is evaluated. The result of evaluating <code>rhs</code> is the
result of the <code>&amp;&amp;</code> operation.</li></ul>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The left-hand side of the operation.
  <strong>rhs:</strong> The right-hand side of the operation.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func &amp;&amp;(lhs: Bool, rhs: @autoclosure () throws -&gt; Bool) -&gt; Bool</code>
    
    
</div></div>
</div>
